﻿@using Orchard.Core.Shapes.Localization
@using System.Globalization

@{

    // prevent the shape from being rendered twice in a page
    if (WorkContext.GetState<object>("TimePickerLocalization") != null) {
        return;
    }

    WorkContext.SetState("TimePickerLocalization", new object());
        
    Style.Require("jQueryUI_TimePicker");
    Script.Require("jQueryUI_TimePicker");

    var cultureInfo = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);
    
    var timeFormat = cultureInfo.DateTimeFormat.ShortTimePattern
        .Replace("H", "h");

    var ampm = cultureInfo.DateTimeFormat.ShortTimePattern.Contains("H") ? "false" : "true";
}

<script type="text/javascript">
//<![CDATA[
    $(function() {

        $.timepicker.regional[''] = {
            timeOnlyTitle: '@T("Choose time")',
            timeText: '@T("Time")',
            hourText: '@T("Hour")',
            minuteText: '@T("Minute")',
            currentText: '@T("Now")', // Display text for current time link
            closeText: '@T("Done")', // Display text for close link
            timeFormat: '@timeFormat',
            amNames: ['@cultureInfo.DateTimeFormat.AMDesignator', 'AM', 'A'],
            pmNames: ['@cultureInfo.DateTimeFormat.PMDesignator', 'PM', 'P'],
            ampm: @ampm
        };

        $.timepicker.setDefaults($.timepicker.regional['']);
    })
//]]>
</script>